#include<bits/stdc++.h>
#define pint pair<int,int>
#define xx first
#define yy second
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline ll read(){
    ll xx=0;short flag=1;char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')flag=-1;
        ch=getchar();
    }
    while('0'<=ch&&ch<='9'){
        xx=(xx<<3)+(xx<<1)+ch-'0';
        ch=getchar();
    }
    return xx*flag;
}
int n,m,l,vmax;
struct node{
    int d,v,a;
    int ll,rr;
    int cnt;
}cars[100005];
int fx[1000005];

int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int T=read();
    while(T--){
        n=read(),m=read(),l=read(),vmax=read();
        for(int i=1;i<=n;i++){
            cars[i]={(int)read(),(int)read(),(int)read(),-1,-1,0};
            if(cars[i].v>vmax){
                if(cars[i].a>0)cars[i].ll=cars[i].d,cars[i].rr=l;
                else if(cars[i].a<0){
                    cars[i].ll=cars[i].d,cars[i].rr=cars[i].d+ceill((vmax*vmax-cars[i].v*cars[i].v)*1.0/(2*cars[i].a))-1;
                }else cars[i].ll=cars[i].d,cars[i].rr=l;
            }else if(cars[i].v<vmax){
                if(cars[i].a>0){
                    cars[i].ll=cars[i].d+floor((vmax*vmax-cars[i].v*cars[i].v)*1.0/(2*cars[i].a))+1;
                    if(cars[i].ll>l)cars[i].ll=0;
                    else cars[i].rr=l;
                }
            }else{
                if(cars[i].a>0) cars[i].ll=cars[i].d+1,cars[i].rr=l;
            }
            if(cars[i].ll!=-1&&cars[i].rr!=-1){
                fx[cars[i].ll]++,fx[cars[i].rr+1]--;
            }
        }
        for(int i=1;i<=l;i++)fx[i]+=fx[i-1];
        //for(int i=1;i<=n;i++)cout<<cars[i].d<<' '<<cars[i].v<<' '<<cars[i].a<<' '<<cars[i].ll<<' '<<cars[i].rr<<endl;
        vector<int> v;
        for(int i=1;i<=m;i++){
            v.push_back(read());
        }
        int ans1=0,ans2=0;
        for(int i=1;i<=n;i++){
            int tl=lower_bound(v.begin(),v.end(),cars[i].ll)-v.begin();
            int tr=upper_bound(v.begin(),v.end(),cars[i].rr)-v.begin()-1;
            if(tl<=tr){
                ans1++;
                cars[i].cnt=tr-tl+1;
                // cout<<i<<' '<<tl<<' '<<tr<<endl;
            }
        }
        for(auto i:v){
            bool flag=1;
            for(int j=1;j<=n;j++){
                if(cars[j].ll<=i&&i<=cars[j].rr){
                    if(cars[j].cnt==1){
                        flag=0;
                        break;
                    }
                }
            }
            if(flag&&fx[i]){
                for(int j=1;j<=n;j++){
                    if(cars[j].ll<=i&&i<=cars[j].rr&&cars[j].cnt==1){
                        cars[j].cnt--;
                    }
                }
                ans2++;
                //cout<<i<<' ';
            }
        }
        cout<<ans1<<' '<<ans2<<endl;
    }
    
    return 0;
}